package com.maxlen.ware.config;

import com.maxlen.common.rabbitMQConstant.RabbitMQConfigConstant;
import com.maxlen.common.rabbitMQConstant.WareRabbitMQConstant;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class MyMQConfig {

    @Bean
    public TopicExchange topicExchange(){
        return new TopicExchange(WareRabbitMQConstant.WARE_EVENT_EXCHANGE, true, false);
    }

    @Bean
    public Queue wareStockDelayQueue(){
        Map<String, Object> map = new HashMap<>();
        map.put(RabbitMQConfigConstant.X_DEAD_LETTER_EXCHANGE, WareRabbitMQConstant.WARE_EVENT_EXCHANGE);
        map.put(RabbitMQConfigConstant.X_DEAD_LETTER_ROUTING_KEY, WareRabbitMQConstant.WARE_STOCK_RELEASE_BINDING);
        map.put(RabbitMQConfigConstant.X_MESSAGE_TTL, 20000);
        return new Queue(WareRabbitMQConstant.WARE_STOCK_DELAY_QUEUE, true, false, false, map);
    }

    @Bean
    public Queue wareStockReleaseQueue(){
        return new Queue(WareRabbitMQConstant.WARE_STOCK_RELEASE_QUEUE, true, false, false);
    }

    @Bean
    public Binding wareStockDelayBinding(){
        return new Binding(
                WareRabbitMQConstant.WARE_STOCK_DELAY_QUEUE,
                Binding.DestinationType.QUEUE,
                WareRabbitMQConstant.WARE_EVENT_EXCHANGE,
                WareRabbitMQConstant.WARE_STOCK_DELAY_BINDING,
                null);
    }

    @Bean
    public Binding wareStockReleaseBinding(){
        return new Binding(
                WareRabbitMQConstant.WARE_STOCK_RELEASE_QUEUE,
                Binding.DestinationType.QUEUE,
                WareRabbitMQConstant.WARE_EVENT_EXCHANGE,
                WareRabbitMQConstant.WARE_STOCK_RELEASE_BINDING,
                null);
    }

}
